package com.example.yiqiuser.service.impl;
import com.example.yiqiuser.dao.HelpDao;
import com.example.yiqiuser.entity.Help;
import com.example.yiqiuser.service.HelpService;
import com.example.yiqiuser.util.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: yiqiuser
 * @description:
 * @author: 诸葛龙辰
 * @create: 2023-04-01 10:54
 * @version:
 **/
@Service
public class HelpServiceImpl implements HelpService {
    @Resource
    private HelpDao helpDao;
    /**
     * 分页查询
     * @param page
     * @return
     */
    @Override
    public PageInfo queryPage(Page<Help> page) {
        PageHelper.startPage(page.getPageNo(), page.getPageSize());
        return new PageInfo(helpDao.queryByParam(page.getData()));
    }

    /**
     * 查询所有
     * @return
     */
    @Override
    public List<Help> queryAll() {
        return helpDao.queryAll();
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Override
    public Help queryById(Integer id) {
        List<Help> helpList = helpDao.queryById(id);
        if (helpList!=null&&helpList.size()>0){
            return helpList.get(0);
        }
        return null;
    }

    /**
     * 添加
     * @param help
     * @return
     */
    @Override
    public int add(Help help) {
        return helpDao.add(help);
    }

    /**
     * 更改
     * @param help
     * @return
     */
    @Override
    public int update(Help help) {
        return helpDao.update(help);
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @Override
    public int deleteById(Integer id) {
        return helpDao.deleteById(id);
    }
}
